package com.rattsoftware.server.dao.hibernate;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.googlecode.genericdao.search.Search;
import com.googlecode.genericdao.search.SearchResult;
import com.rattsoftware.server.admin.model.Room;
import com.rattsoftware.server.admin.model.paging.PagingLoadConfig;
import com.rattsoftware.server.admin.model.paging.PagingLoadResult;
import com.rattsoftware.server.dao.RoomDAO;

/**
 * Provides a hibernate implementation
 * of the <code>RoomDAO</code> data access <code> interface.</code>
 */
@Repository("roomDAO")
public class HibernateRoomDAO extends BaseDAOImpl<Room> implements RoomDAO {

	@Override
	public void deleteRoom(Room room) {
		remove(room);
	}

	@Override
	public PagingLoadResult<Room> getRoomList(PagingLoadConfig pagingLoadConfig) {
		Search roomSearch = getSearchFromLoadConfig(pagingLoadConfig, "id");
		SearchResult<Room> result = searchAndCount(roomSearch);
		return getPagingLoadResult(pagingLoadConfig, result);
	}

	@Override
	public Room getRoomViaRoomId(Integer id) {
		return super.find(id);
	}

	@Override
	public Room getRoomViaRoomNo(int roomNo) {
		return super.searchUniqueByPropertyEqual("room_number", roomNo);
	}

	@Override
	public List<Room> getRooms() {
		Search s = new Search();
		s.addSort("name", false);
		return search(s);
	}

	@Override
	public void saveRoom(Room room) {
		save(room);
	}
}